﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.Revit;
using HYRevitCode.BoundingBoxUtility;
using HYRevitCode.RevitTopologySuite;
using QuickModel.CommonTrans;
using QuickModel.InteractiveOperation.CmdTestInteractiveOperation;
using QuickModel.Models;
using QuickModel.QuickModelFrame;
using Transfer.Utils;

namespace QuickModel.LastFastModeling
{
	[Rebuilder(RebuilderName = "LastFastModeling")]
	public class LastFastModelingRebuilder : IRevitModelRebuilder
	{
		public bool TryRebuildRevitModel(Autodesk.Revit.DB.Document inputDoc, RevitModelRequest inputReqeust, out BuildData buildData)
		{
			buildData = new BuildData();
			bool result;
			try
			{
				LastFastModelingRevitModelRequest lastFastModelingRevitModelRequest = inputReqeust as LastFastModelingRevitModelRequest;
				bool flag = lastFastModelingRevitModelRequest == null;
				if (flag)
				{
					result = false;
				}
				else
				{
					QuickModelingPara quickModelingPara = lastFastModelingRevitModelRequest.ViewParas as QuickModelingPara;
					bool flag2 = quickModelingPara == null || quickModelingPara.SelectedEquipData == null;
					if (flag2)
					{
						result = false;
					}
					else
					{
						string a = quickModelingPara.SpecialtyName + "@" + quickModelingPara.SelectedEquipData.Name;
						string text = string.Empty;
						bool flag3 = false;
						try
						{
							bool flag4 = a == "给排水@消火栓";
							if (flag4)
							{
								flag3 = this.ReplaceHydrantBlock(inputDoc, lastFastModelingRevitModelRequest.PlaceFs, lastFastModelingRevitModelRequest.Block, out buildData);
							}
							else
							{
								bool flag5 = a == "给排水@灭火器";
								if (flag5)
								{
									flag3 = this.ReplaceFireExtinguisherBlock(inputDoc, lastFastModelingRevitModelRequest.PlaceFs, lastFastModelingRevitModelRequest.Block, out buildData);
									lastFastModelingRevitModelRequest.CreatedElement = (flag3 ? buildData.CreatedElement : null);
								}
								else
								{
									bool flag6 = a == "暖通@风口";
									if (flag6)
									{
										flag3 = this.ReplaceWindMouthBlock(inputDoc, lastFastModelingRevitModelRequest.PlaceFs, lastFastModelingRevitModelRequest.Block, quickModelingPara, out buildData);
									}
									else
									{
										bool flag7 = a == "暖通@风机盘管";
										if (flag7)
										{
											flag3 = this.ReplaceDuctCoilBlock(inputDoc, lastFastModelingRevitModelRequest, quickModelingPara, out buildData);
										}
										else
										{
											bool flag8 = a == "暖通@室内机";
											if (flag8)
											{
												flag3 = this.ReplaceInDoorUnitByCurve(inputDoc, lastFastModelingRevitModelRequest, quickModelingPara, out buildData);
											}
											else
											{
												bool flag9 = a == "暖通@散热器";
												if (flag9)
												{
													flag3 = this.ReplaceRadiatorByCurve(inputDoc, lastFastModelingRevitModelRequest, quickModelingPara, out buildData);
												}
												else
												{
													flag3 = this.ReplaceElectricBlock(inputDoc, lastFastModelingRevitModelRequest.PlaceFs, lastFastModelingRevitModelRequest.Block, quickModelingPara, out buildData);
												}
											}
										}
									}
								}
							}
							bool flag10 = !flag3;
							if (flag10)
							{
							}
						}
						catch (Exception ex)
						{
							flag3 = false;
							text = ex.Message;
						}
						finally
						{
						}
						result = flag3;
					}
				}
			}
			catch (Exception)
			{
				result = false;
			}
			return result;
		}

		private bool ReplaceHydrantBlock(Autodesk.Revit.DB.Document doc, FamilySymbol fs, PointPosBlockInfo blockInfo, out BuildData createdData)
		{
			createdData = new BuildData();
			bool flag = blockInfo == null;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				XYZ xyz = BussinessCommon.GetBlockActualLocation(blockInfo);
				xyz = this.RemoveZValue(xyz);
				createdData.CreatedElement = RevitCommonFunctions.NewFamilyInstance(doc, fs, xyz, doc.ActiveView.GenLevel, (Autodesk.Revit.DB.Structure.StructuralType)0);
				bool flag2 = createdData.CreatedElement == null;
				if (flag2)
				{
					result = false;
				}
				else
				{
					createdData.NeedResponse = true;
					doc.Regenerate();
					bool flag3 = false;
					bool flag4 = false;
					this.CheckBlockIsMirrored(blockInfo.UseScale, out flag3, out flag4);
					bool flag5 = flag3;
					if (flag5)
					{
						BussinessCommon.MirrorElement(doc, createdData.CreatedElement, xyz, -1);
					}
					bool flag6 = flag4;
					if (flag6)
					{
						BussinessCommon.MirrorElement(doc, createdData.CreatedElement, xyz, 1);
					}
					double num = blockInfo.Angle + Math.PI;
					num = this.GetRightAngle(num);
					bool flag7 = this.CheckValue(num) != 0;
					if (flag7)
					{
						BussinessCommon.RotateElement(doc, createdData.CreatedElement, num);
					}
					Parameter parameter = createdData.CreatedElement.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM);
					bool flag8 = parameter != null;
					if (flag8)
					{
						parameter.Set(Common.MMToFeet(1100.0));
					}
					result = true;
				}
			}
			return result;
		}

		private bool ReplaceFireExtinguisherBlock(Autodesk.Revit.DB.Document doc, FamilySymbol fs, PointPosBlockInfo blockInfo, out BuildData createdData)
		{
			createdData = new BuildData();
			bool flag = blockInfo == null;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				XYZ xyz = BussinessCommon.GetBlockActualLocation(blockInfo);
				xyz = this.RemoveZValue(xyz);
				createdData.CreatedElement = RevitCommonFunctions.NewFamilyInstance(doc, fs, xyz, doc.ActiveView.GenLevel, (Autodesk.Revit.DB.Structure.StructuralType)0);
				bool flag2 = createdData.CreatedElement == null;
				if (flag2)
				{
					result = false;
				}
				else
				{
					createdData.NeedResponse = true;
					doc.Regenerate();
					bool flag3 = false;
					bool flag4 = false;
					this.CheckBlockIsMirrored(blockInfo.UseScale, out flag3, out flag4);
					bool flag5 = flag3;
					if (flag5)
					{
						BussinessCommon.MirrorElement(doc, createdData.CreatedElement, xyz, -1);
					}
					bool flag6 = flag4;
					if (flag6)
					{
						BussinessCommon.MirrorElement(doc, createdData.CreatedElement, xyz, 1);
					}
					double num = blockInfo.Angle;
					num = this.GetRightAngle(num);
					bool flag7 = this.CheckValue(num) != 0;
					if (flag7)
					{
						BussinessCommon.RotateElement(doc, createdData.CreatedElement, num);
					}
					result = true;
				}
			}
			return result;
		}

		private bool ReplaceElectricBlock(Autodesk.Revit.DB.Document doc, FamilySymbol fs, PointPosBlockInfo blockInfo, QuickModelingPara viewParas, out BuildData createdData)
		{
			createdData = new BuildData();
			bool flag = blockInfo == null;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				XYZ location = new XYZ(blockInfo.UseLocationPoint.X, blockInfo.UseLocationPoint.Y, 0.0);
				createdData.CreatedElement = RevitCommonFunctions.NewFamilyInstance(doc, fs, location, doc.ActiveView.GenLevel, (Autodesk.Revit.DB.Structure.StructuralType)0);
				bool flag2 = createdData.CreatedElement == null;
				if (flag2)
				{
					result = false;
				}
				else
				{
					createdData.NeedResponse = true;
					doc.Regenerate();
					bool flag3 = false;
					bool flag4 = false;
					this.CheckBlockIsMirrored(blockInfo.UseScale, out flag3, out flag4);
					bool flag5 = flag3;
					if (flag5)
					{
						BussinessCommon.MirrorElement(doc, createdData.CreatedElement, location, -1);
					}
					bool flag6 = flag4;
					if (flag6)
					{
						BussinessCommon.MirrorElement(doc, createdData.CreatedElement, location, 1);
					}
					double num = blockInfo.Angle;
					num = this.GetRightAngle(num);
					bool flag7 = this.CheckValue(num) != 0;
					if (flag7)
					{
						BussinessCommon.RotateElement(doc, createdData.CreatedElement, num);
					}
					ElectricViewPara electricViewPara = viewParas.ChildViewPara as ElectricViewPara;
					bool flag8 = electricViewPara != null;
					if (flag8)
					{
						Parameter parameter = createdData.CreatedElement.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM);
						bool flag9 = parameter != null;
						if (flag9)
						{
							parameter.Set(Common.MMToFeet(electricViewPara.Offset * 1000.0));
						}
					}
					result = true;
				}
			}
			return result;
		}

		private bool ReplaceWindMouthBlock(Autodesk.Revit.DB.Document doc, FamilySymbol fs, PointPosBlockInfo blockInfo, QuickModelingPara viewParas, out BuildData createdData)
		{
			createdData = new BuildData();
			bool flag = blockInfo == null;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				WindMouthPara windMouthPara = viewParas.ChildViewPara as WindMouthPara;
				bool flag2 = windMouthPara == null;
				if (flag2)
				{
					result = false;
				}
				else
				{
					bool flag3 = fs == null || fs.Family == null;
					if (flag3)
					{
						result = false;
					}
					else
					{
						PointPosBlockWindMouthInfo pointPosBlockWindMouthInfo = blockInfo as PointPosBlockWindMouthInfo;
						string name = fs.Family.Name;
						List<CurveOutBoxType> curveOutBoxTypeByFamily = this.GetCurveOutBoxTypeByFamily(name);
						bool flag4 = !pointPosBlockWindMouthInfo.GetBlockWidthAndHeight(curveOutBoxTypeByFamily);
						if (flag4)
						{
							result = false;
						}
						else
						{
							XYZ xyz = pointPosBlockWindMouthInfo.BlockPlaceLocation;
							xyz = this.RemoveZValue(xyz);
							createdData.CreatedElement = RevitCommonFunctions.NewFamilyInstance(doc, fs, xyz, doc.ActiveView.GenLevel, (Autodesk.Revit.DB.Structure.StructuralType)0);
							bool flag5 = createdData.CreatedElement == null;
							if (flag5)
							{
								result = false;
							}
							else
							{
								createdData.NeedResponse = true;
								bool flag6 = !windMouthPara.IsCurDoc;
								if (flag6)
								{
									this.SetWindMouthArrowType(createdData.CreatedElement, windMouthPara.ArrowType);
									bool flag7 = this.SetWindMouthSize(createdData.CreatedElement, pointPosBlockWindMouthInfo);
									bool flag8 = !flag7;
									if (flag8)
									{
										return false;
									}
								}
								doc.Regenerate();
								ToleranceManger toleranceManger = ToleranceManger.GetToleranceManger();
								double tolerance = toleranceManger.GetTolerance("末端快模-距离公差");
								XYZ xyz2 = XYZ.Zero;
								bool flag9 = name == "侧风口";
								if (flag9)
								{
									double paraDoubleValue = this.GetParaDoubleValue(createdData.CreatedElement, "风口厚度");
									double num = paraDoubleValue / 2.0;
									bool flag10 = !Geometry.IsEqual(num, tolerance);
									if (flag10)
									{
										xyz2 = num * XYZ.BasisX;
									}
								}
								else
								{
									bool flag11 = name == "防火风口";
									if (flag11)
									{
										double paraDoubleValue2 = this.GetParaDoubleValue(createdData.CreatedElement, "风口厚度");
										double paraDoubleValue3 = this.GetParaDoubleValue(createdData.CreatedElement, "面板厚度");
										xyz2 = -(paraDoubleValue2 / 2.0 - paraDoubleValue3) * XYZ.BasisY;
									}
								}
								xyz2 = this.RemoveZValue(xyz2);
								bool flag12 = !xyz2.IsAlmostEqualTo(XYZ.Zero);
								if (flag12)
								{
									BussinessCommon.MoveElement(doc, createdData.CreatedElement, xyz2);
								}
								bool flag13 = false;
								bool flag14 = false;
								this.CheckBlockIsMirrored(blockInfo.UseScale, out flag13, out flag14);
								bool flag15 = flag13;
								if (flag15)
								{
									BussinessCommon.MirrorElement(doc, createdData.CreatedElement, xyz, -1);
								}
								bool flag16 = flag14;
								if (flag16)
								{
									BussinessCommon.MirrorElement(doc, createdData.CreatedElement, xyz, 1);
								}
								double num2 = blockInfo.Angle;
								num2 = this.GetRightAngle(num2);
								bool flag17 = this.CheckValue(num2) != 0;
								if (flag17)
								{
									BussinessCommon.RotateElement(doc, createdData.CreatedElement, xyz, num2);
								}
								Parameter parameter = createdData.CreatedElement.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM);
								bool flag18 = parameter != null;
								if (flag18)
								{
									parameter.Set(Common.MMToFeet(windMouthPara.Offset * 1000.0));
								}
								result = true;
							}
						}
					}
				}
			}
			return result;
		}

		private bool ReplaceInDoorUnitByCurve(Autodesk.Revit.DB.Document doc, LastFastModelingRevitModelRequest useRequest, QuickModelingPara viewParas, out BuildData createdData)
		{
			createdData = new BuildData();
			FamilySymbol placeFs = useRequest.PlaceFs;
			List<Curve> curves = useRequest.Curves;
			double curveMultiple = useRequest.CurveMultiple;
			bool flag = curves.IsEmpty<Curve>();
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				InDoorUnitPara inDoorUnitPara = viewParas.ChildViewPara as InDoorUnitPara;
				bool flag2 = inDoorUnitPara == null;
				if (flag2)
				{
					result = false;
				}
				else
				{
					bool flag3 = placeFs == null || placeFs.Family == null;
					if (flag3)
					{
						result = false;
					}
					else
					{
						string name = placeFs.Family.Name;
						XYZ xyz = this.GetCurvesCenterLocation(curves);
						bool flag4 = xyz == null;
						if (flag4)
						{
							result = false;
						}
						else
						{
							xyz = this.RemoveZValue(xyz);
							xyz = this.ScalePoint(xyz, curveMultiple);
							createdData.CreatedElement = RevitCommonFunctions.NewFamilyInstance(doc, placeFs, xyz, doc.ActiveView.GenLevel, (Autodesk.Revit.DB.Structure.StructuralType)0);
							bool flag5 = createdData.CreatedElement == null;
							if (flag5)
							{
								result = false;
							}
							else
							{
								createdData.NeedResponse = true;
								bool flag6 = !inDoorUnitPara.IsCurDoc;
								if (flag6)
								{
									this.SetInDoorUnitParas(createdData.CreatedElement, inDoorUnitPara.Paras);
								}
								doc.Regenerate();
								XYZ xyz2 = XYZ.Zero;
								bool flag7 = name == "吊顶落地式_多联机" || name == "壁挂式_多联机室内机(NE)";
								if (flag7)
								{
									double paraDoubleValue = this.GetParaDoubleValue(createdData.CreatedElement, "宽度");
									xyz2 = paraDoubleValue / 2.0 * XYZ.BasisY;
								}
								xyz2 = this.RemoveZValue(xyz2);
								bool flag8 = !xyz2.IsAlmostEqualTo(XYZ.Zero);
								if (flag8)
								{
									BussinessCommon.MoveElement(doc, createdData.CreatedElement, xyz2);
								}
								bool flag9 = name == "标准型风管天井式_多联机室内机(NE)" || name == "薄型风管天井式标配水泵_多联机室内机(NE)" || name == "薄型风管天井式标准机型_多联机室内机";
								double num;
								if (flag9)
								{
									num = this.GetDuctCoilRotateAngle(curves, doc);
								}
								else
								{
									bool flag10 = name == "高静压风管天井式_多联机" || name == "壁挂式_多联机室内机(NE)";
									if (flag10)
									{
										num = this.GetDuctCoilRotateAngle(curves, null);
										num += Math.PI;
									}
									else
									{
										num = this.GetDuctCoilRotateAngleByMaxCurve(curves);
									}
								}
								num = this.GetRightAngle(num);
								bool flag11 = this.CheckValue(num) != 0;
								if (flag11)
								{
									BussinessCommon.RotateElement(doc, createdData.CreatedElement, xyz, num);
								}
								Parameter parameter = createdData.CreatedElement.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM);
								bool flag12 = parameter != null;
								if (flag12)
								{
									parameter.Set(Common.MMToFeet(inDoorUnitPara.Offset * 1000.0));
								}
								result = true;
							}
						}
					}
				}
			}
			return result;
		}

		private bool ReplaceRadiatorByCurve(Autodesk.Revit.DB.Document doc, LastFastModelingRevitModelRequest useRequest, QuickModelingPara viewParas, out BuildData createdData)
		{
			createdData = new BuildData();
			FamilySymbol placeFs = useRequest.PlaceFs;
			List<Curve> curves = useRequest.Curves;
			double curveMultiple = useRequest.CurveMultiple;
			bool flag = curves.IsEmpty<Curve>();
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				RadiatorPara radiatorPara = viewParas.ChildViewPara as RadiatorPara;
				bool flag2 = radiatorPara == null;
				if (flag2)
				{
					result = false;
				}
				else
				{
					bool flag3 = placeFs == null || placeFs.Family == null;
					if (flag3)
					{
						result = false;
					}
					else
					{
						string name = placeFs.Family.Name;
						XYZ xyz = this.GetCurvesCenterLocation(curves);
						bool flag4 = xyz == null;
						if (flag4)
						{
							result = false;
						}
						else
						{
							xyz = this.RemoveZValue(xyz);
							xyz = this.ScalePoint(xyz, curveMultiple);
							createdData.CreatedElement = RevitCommonFunctions.NewFamilyInstance(doc, placeFs, xyz, doc.ActiveView.GenLevel, (Autodesk.Revit.DB.Structure.StructuralType)0);
							bool flag5 = createdData.CreatedElement == null;
							if (flag5)
							{
								result = false;
							}
							else
							{
								createdData.NeedResponse = true;
								bool flag6 = !radiatorPara.IsCurDoc;
								if (flag6)
								{
									this.SetPara(createdData.CreatedElement, "散热器片数", radiatorPara.LabelCount);
								}
								doc.Regenerate();
								XYZ xyz2 = XYZ.Zero;
								bool flag7 = name.Contains("NDRT");
								if (flag7)
								{
									double paraDoubleValue = this.GetParaDoubleValue(createdData.CreatedElement, "集液管半径");
									xyz2 = -paraDoubleValue * XYZ.BasisY;
								}
								else
								{
									double paraDoubleValue2 = this.GetParaDoubleValue(createdData.CreatedElement, "散热器宽度");
									xyz2 = -(paraDoubleValue2 / 2.0) * XYZ.BasisY;
								}
								xyz2 = this.RemoveZValue(xyz2);
								bool flag8 = !xyz2.IsAlmostEqualTo(XYZ.Zero);
								if (flag8)
								{
									BussinessCommon.MoveElement(doc, createdData.CreatedElement, xyz2);
								}
								FamilyInstance familyInstance = createdData.CreatedElement as FamilyInstance;
								XYZ facingOrientation = familyInstance.FacingOrientation;
								UIApplication uiApp = new UIApplication(doc.Application);
								this.SetRadiatorTypeAndVector(uiApp, facingOrientation, radiatorPara.InstallType, familyInstance);
								this.RadiatorMirror(radiatorPara.RotateType, familyInstance, xyz, doc);
								ToleranceManger toleranceManger = ToleranceManger.GetToleranceManger();
								double tolerance = toleranceManger.GetTolerance("末端快模-角度公差");
								double num = this.GetRadiatorRotateAngleByMaxCurve(curves, tolerance);
								num = this.GetRightAngle(num);
								bool flag9 = this.CheckValue(num) != 0;
								if (flag9)
								{
									BussinessCommon.RotateElement(doc, createdData.CreatedElement, xyz, num);
								}
								Parameter parameter = createdData.CreatedElement.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM);
								bool flag10 = parameter != null;
								if (flag10)
								{
									parameter.Set(Common.MMToFeet(radiatorPara.Offset * 1000.0));
								}
								bool isLabelCount = radiatorPara.IsLabelCount;
								if (isLabelCount)
								{
									this.SetRadiatorDimension(familyInstance, doc, radiatorPara.LabelType == "上标");
								}
								result = true;
							}
						}
					}
				}
			}
			return result;
		}

		private bool ReplaceDuctCoilBlock(Autodesk.Revit.DB.Document doc, LastFastModelingRevitModelRequest useRequest, QuickModelingPara viewParas, out BuildData createdData)
		{
			createdData = new BuildData();
			bool flag = useRequest.Block != null;
			bool result;
			if (flag)
			{
				result = this.ReplaceDuctCoilByBlock(doc, useRequest, viewParas, out createdData);
			}
			else
			{
				result = this.ReplaceDuctCoilByCurve(doc, useRequest, viewParas, out createdData);
			}
			return result;
		}

		private bool ReplaceDuctCoilByBlock(Autodesk.Revit.DB.Document doc, LastFastModelingRevitModelRequest useRequest, QuickModelingPara viewParas, out BuildData createdData)
		{
			createdData = new BuildData();
			FamilySymbol placeFs = useRequest.PlaceFs;
			PointPosBlockDuctCoilInfo pointPosBlockDuctCoilInfo = useRequest.Block as PointPosBlockDuctCoilInfo;
			bool flag = pointPosBlockDuctCoilInfo == null;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				DraughtFanPipePara draughtFanPipePara = viewParas.ChildViewPara as DraughtFanPipePara;
				bool flag2 = draughtFanPipePara == null;
				if (flag2)
				{
					result = false;
				}
				else
				{
					bool flag3 = placeFs == null || placeFs.Family == null;
					if (flag3)
					{
						result = false;
					}
					else
					{
						string name = placeFs.Family.Name;
						XYZ xyz = pointPosBlockDuctCoilInfo.UseLocationPoint;
						xyz = this.RemoveZValue(xyz);
						createdData.CreatedElement = RevitCommonFunctions.NewFamilyInstance(doc, placeFs, xyz, doc.ActiveView.GenLevel, (Autodesk.Revit.DB.Structure.StructuralType)0);
						bool flag4 = createdData.CreatedElement == null;
						if (flag4)
						{
							result = false;
						}
						else
						{
							createdData.NeedResponse = true;
							bool flag5 = !draughtFanPipePara.IsCurDoc;
							if (flag5)
							{
								this.SettingParameter(createdData.CreatedElement, draughtFanPipePara.Paras, draughtFanPipePara.EcpPara);
							}
							doc.Regenerate();
							XYZ xyz2 = XYZ.Zero;
							bool flag6 = name != "吸顶式风机盘管";
							if (flag6)
							{
								double paraDoubleValue = this.GetParaDoubleValue(createdData.CreatedElement, "长度");
								double paraDoubleValue2 = this.GetParaDoubleValue(createdData.CreatedElement, "宽度");
								xyz2 = -(paraDoubleValue / 2.0 * XYZ.BasisX + paraDoubleValue2 / 2.0 * XYZ.BasisY);
							}
							xyz2 = this.RemoveZValue(xyz2);
							bool flag7 = !xyz2.IsAlmostEqualTo(XYZ.Zero);
							if (flag7)
							{
								BussinessCommon.MoveElement(doc, createdData.CreatedElement, xyz2);
							}
							double num = this.GetAngleFromTwoVector(pointPosBlockDuctCoilInfo.BlockAxisY, XYZ.BasisY);
							num = this.GetRightAngle(num);
							bool flag8 = this.CheckValue(num) != 0;
							if (flag8)
							{
								BussinessCommon.RotateElement(doc, createdData.CreatedElement, xyz, num);
							}
							Parameter parameter = createdData.CreatedElement.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM);
							bool flag9 = parameter != null;
							if (flag9)
							{
								parameter.Set(Common.MMToFeet(draughtFanPipePara.Offset * 1000.0));
							}
							result = true;
						}
					}
				}
			}
			return result;
		}

		private bool ReplaceDuctCoilByCurve(Autodesk.Revit.DB.Document doc, LastFastModelingRevitModelRequest useRequest, QuickModelingPara viewParas, out BuildData createdData)
		{
			createdData = new BuildData();
			FamilySymbol placeFs = useRequest.PlaceFs;
			List<Curve> curves = useRequest.Curves;
			double curveMultiple = useRequest.CurveMultiple;
			bool flag = curves.IsEmpty<Curve>();
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				DraughtFanPipePara draughtFanPipePara = viewParas.ChildViewPara as DraughtFanPipePara;
				bool flag2 = draughtFanPipePara == null;
				if (flag2)
				{
					result = false;
				}
				else
				{
					bool flag3 = placeFs == null || placeFs.Family == null;
					if (flag3)
					{
						result = false;
					}
					else
					{
						string name = placeFs.Family.Name;
						XYZ xyz = this.GetCurvesCenterLocation(curves);
						bool flag4 = xyz == null;
						if (flag4)
						{
							result = false;
						}
						else
						{
							xyz = this.RemoveZValue(xyz);
							xyz = this.ScalePoint(xyz, curveMultiple);
							createdData.CreatedElement = RevitCommonFunctions.NewFamilyInstance(doc, placeFs, xyz, doc.ActiveView.GenLevel, (Autodesk.Revit.DB.Structure.StructuralType)0);
							bool flag5 = createdData.CreatedElement == null;
							if (flag5)
							{
								result = false;
							}
							else
							{
								createdData.NeedResponse = true;
								bool flag6 = !draughtFanPipePara.IsCurDoc;
								if (flag6)
								{
									this.SettingParameter(createdData.CreatedElement, draughtFanPipePara.Paras, draughtFanPipePara.EcpPara);
								}
								doc.Regenerate();
								XYZ xyz2 = XYZ.Zero;
								bool flag7 = name != "吸顶式风机盘管";
								if (flag7)
								{
									double paraDoubleValue = this.GetParaDoubleValue(createdData.CreatedElement, "长度");
									double paraDoubleValue2 = this.GetParaDoubleValue(createdData.CreatedElement, "宽度");
									xyz2 = -(paraDoubleValue / 2.0 * XYZ.BasisX + paraDoubleValue2 / 2.0 * XYZ.BasisY);
								}
								xyz2 = this.RemoveZValue(xyz2);
								bool flag8 = !xyz2.IsAlmostEqualTo(XYZ.Zero);
								if (flag8)
								{
									BussinessCommon.MoveElement(doc, createdData.CreatedElement, xyz2);
								}
								bool flag9 = name == "卧式暗装风机盘管_右接管" || name == "卧式暗装风机盘管_左接管";
								double num;
								if (flag9)
								{
									num = this.GetDuctCoilRotateAngle(curves, null);
								}
								else
								{
									num = this.GetDuctCoilRotateAngleByMaxCurve(curves);
								}
								num = this.GetRightAngle(num);
								bool flag10 = this.CheckValue(num) != 0;
								if (flag10)
								{
									BussinessCommon.RotateElement(doc, createdData.CreatedElement, xyz, num);
								}
								Parameter parameter = createdData.CreatedElement.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM);
								bool flag11 = parameter != null;
								if (flag11)
								{
									parameter.Set(Common.MMToFeet(draughtFanPipePara.Offset * 1000.0));
								}
								result = true;
							}
						}
					}
				}
			}
			return result;
		}

		private void SettingParameter(Element item, EquipmentCoilSetDetailParas paras, EquipmentCoilParameter ecp)
		{
			bool flag = item == null || paras == null || ecp == null;
			if (!flag)
			{
				try
				{
					bool flag2 = paras != null;
					if (flag2)
					{
						Parameter parameter = item.GetParameter("统计名称");
						bool flag3 = parameter != null && !parameter.IsReadOnly && paras.Name != "";
						if (flag3)
						{
							parameter.Set(paras.Name);
						}
						Parameter parameter2 = item.GetParameter("长度");
						bool flag4 = parameter2 != null && !parameter2.IsReadOnly && paras.Length != 0.0;
						if (flag4)
						{
							parameter2.Set(UnitConvert.CovertToAPI(paras.Length, (Autodesk.Revit.DB.DisplayUnitType)2));
						}
						Parameter parameter3 = item.GetParameter("宽度");
						bool flag5 = parameter3 != null && !parameter3.IsReadOnly && paras.Width != 0.0;
						if (flag5)
						{
							parameter3.Set(UnitConvert.CovertToAPI(paras.Width, (Autodesk.Revit.DB.DisplayUnitType)2));
						}
						Parameter parameter4 = item.GetParameter("高度");
						bool flag6 = parameter4 != null && !parameter4.IsReadOnly && paras.High != 0.0;
						if (flag6)
						{
							parameter4.Set(UnitConvert.CovertToAPI(paras.High, (Autodesk.Revit.DB.DisplayUnitType)2));
						}
						Parameter parameter5 = item.GetParameter("厚度");
						bool flag7 = parameter5 != null && !parameter5.IsReadOnly && paras.High != 0.0;
						if (flag7)
						{
							parameter5.Set(UnitConvert.CovertToAPI(paras.High, (Autodesk.Revit.DB.DisplayUnitType)2));
						}
						Parameter parameter6 = item.GetParameter("制冷量");
						bool flag8 = parameter6 != null && !parameter6.IsReadOnly;
						if (flag8)
						{
							parameter6.Set(UnitConvert.CovertToAPI(paras.CoolPower, (Autodesk.Revit.DB.DisplayUnitType)39));
						}
						Parameter parameter7 = item.GetParameter("制热量");
						bool flag9 = parameter7 != null && !parameter7.IsReadOnly;
						if (flag9)
						{
							parameter7.Set(UnitConvert.CovertToAPI(paras.HotPower, (Autodesk.Revit.DB.DisplayUnitType)39));
						}
						Parameter parameter8 = item.GetParameter("风量");
						bool flag10 = parameter8 != null && !parameter8.IsReadOnly;
						if (flag10)
						{
							parameter8.Set(UnitConvert.CovertToAPI(paras.Wind, (Autodesk.Revit.DB.DisplayUnitType)66));
						}
						Parameter parameter9 = item.GetParameter("水流量");
						bool flag11 = parameter9 != null && !parameter9.IsReadOnly;
						if (flag11)
						{
							parameter9.Set(UnitConvert.CovertToAPI(paras.Water / 1000.0, (Autodesk.Revit.DB.DisplayUnitType)66));
						}
						Parameter parameter10 = item.GetParameter("进水口接管管径");
						bool flag12 = parameter10 != null && !parameter10.IsReadOnly && paras.PipeInDim != 0.0;
						if (flag12)
						{
							parameter10.Set(UnitConvert.CovertToAPI(paras.PipeInDim, (Autodesk.Revit.DB.DisplayUnitType)2));
						}
						Parameter parameter11 = item.GetParameter("出水口接管管径");
						bool flag13 = parameter11 != null && !parameter11.IsReadOnly && paras.PipeOutDim != 0.0;
						if (flag13)
						{
							parameter11.Set(UnitConvert.CovertToAPI(paras.PipeOutDim, (Autodesk.Revit.DB.DisplayUnitType)2));
						}
						Parameter parameter12 = item.GetParameter("冷凝水接管管径");
						bool flag14 = parameter12 != null && !parameter12.IsReadOnly && paras.PipeCoolDim != 0.0;
						if (flag14)
						{
							parameter12.Set(UnitConvert.CovertToAPI(paras.PipeCoolDim, (Autodesk.Revit.DB.DisplayUnitType)2));
						}
						Parameter parameter13 = item.GetParameter("送风口宽度");
						bool flag15 = parameter13 != null && !parameter13.IsReadOnly && paras.DuctSupplyWidth != 0.0;
						if (flag15)
						{
							parameter13.Set(UnitConvert.CovertToAPI(paras.DuctSupplyWidth, (Autodesk.Revit.DB.DisplayUnitType)2));
						}
						Parameter parameter14 = item.GetParameter("送风口高度");
						bool flag16 = parameter14 != null && !parameter14.IsReadOnly && paras.DuctSupplyHigh != 0.0;
						if (flag16)
						{
							parameter14.Set(UnitConvert.CovertToAPI(paras.DuctSupplyHigh, (Autodesk.Revit.DB.DisplayUnitType)2));
						}
						Parameter parameter15 = item.GetParameter("回风口宽度");
						bool flag17 = parameter15 != null && !parameter15.IsReadOnly && paras.Length / 2.0 != 0.0;
						if (flag17)
						{
							parameter15.Set(UnitConvert.CovertToAPI(paras.Length / 2.0, (Autodesk.Revit.DB.DisplayUnitType)2));
						}
						Parameter parameter16 = item.GetParameter("回风口高度");
						bool flag18 = parameter16 != null && !parameter16.IsReadOnly && paras.Width / 2.0 != 0.0;
						if (flag18)
						{
							parameter16.Set(UnitConvert.CovertToAPI(paras.Width / 2.0, (Autodesk.Revit.DB.DisplayUnitType)2));
						}
					}
					bool flag19 = ecp != null;
					if (flag19)
					{
						Parameter parameter17 = item.GetParameters("风机盘管厂家").FirstOrDefault<Parameter>();
						bool flag20 = parameter17 != null && !parameter17.IsReadOnly;
						if (flag20)
						{
							parameter17.Set(ecp.Factory);
						}
						Parameter parameter18 = item.GetParameters("风机盘管结构形式").FirstOrDefault<Parameter>();
						bool flag21 = parameter18 != null && !parameter18.IsReadOnly;
						if (flag21)
						{
							parameter18.Set(ecp.StructType);
						}
						Parameter parameter19 = item.GetParameters("风机盘管安装形式").FirstOrDefault<Parameter>();
						bool flag22 = parameter19 != null && !parameter19.IsReadOnly;
						if (flag22)
						{
							parameter19.Set(ecp.InstallType);
						}
						Parameter parameter20 = item.GetParameters("风机盘管型号").FirstOrDefault<Parameter>();
						bool flag23 = parameter20 != null && !parameter20.IsReadOnly;
						if (flag23)
						{
							parameter20.Set(ecp.Name);
						}
					}
				}
				catch (Exception ex)
				{
				}
			}
		}

		private void SetInDoorUnitParas(Element elem, DLJ_IndoorUnit allinUnit)
		{
			bool flag = elem == null || allinUnit == null;
			if (!flag)
			{
				try
				{
					this.SetPara(elem, "产品型号", allinUnit.Model);
					this.SetPara(elem, "生产厂家", allinUnit.Factory);
					this.SetPara(elem, "产品大类", allinUnit.Classify);
					this.SetPara(elem, "设备型式", allinUnit.Type);
					this.SetPara(elem, "制冷量", UnitConvert.CovertToAPI(allinUnit.ColdCapability * 1000.0, (Autodesk.Revit.DB.DisplayUnitType)39));
					this.SetPara(elem, "制热量", UnitConvert.CovertToAPI(allinUnit.HeatCapability * 1000.0, (Autodesk.Revit.DB.DisplayUnitType)39));
					this.SetPara(elem, "电辅制热量", UnitConvert.CovertToAPI(allinUnit.ElectHeat * 1000.0, (Autodesk.Revit.DB.DisplayUnitType)39));
					this.SetPara(elem, "风量", UnitConvert.CovertToAPI(allinUnit.MaxAirVolume, (Autodesk.Revit.DB.DisplayUnitType)66));
					this.SetPara(elem, "静压", UnitConvert.CovertToAPI(allinUnit.MaxPress, (Autodesk.Revit.DB.DisplayUnitType)48));
					this.SetPara(elem, "制冷功率", UnitConvert.CovertToAPI(allinUnit.ColdPower * 1000.0, (Autodesk.Revit.DB.DisplayUnitType)39));
					this.SetPara(elem, "制热功率", UnitConvert.CovertToAPI(allinUnit.HeatPower * 1000.0, (Autodesk.Revit.DB.DisplayUnitType)39));
					this.SetPara(elem, "电压", UnitConvert.CovertToAPI((double)allinUnit.Voltage, (Autodesk.Revit.DB.DisplayUnitType)72));
					this.SetPara(elem, "气管管径", Common.MMToFeet(allinUnit.GasPipeDia));
					this.SetPara(elem, "液管管径", Common.MMToFeet(allinUnit.LiquidPipeDia));
					this.SetPara(elem, "冷凝水管管径", Common.MMToFeet(allinUnit.CondenPipeDia));
					this.SetPara(elem, "重量", allinUnit.Weight);
					this.SetPara(elem, "价格", allinUnit.Price);
					this.SetPara(elem, "噪声", allinUnit.Noise);
					this.SetPara(elem, "备注", allinUnit.Note);
					this.SetPara(elem, "面板长度", Common.MMToFeet((double)allinUnit.PanelLength));
					this.SetPara(elem, "面板宽度", Common.MMToFeet((double)allinUnit.PanelWidth));
					this.SetPara(elem, "面板高度", Common.MMToFeet((double)allinUnit.PanelHeight));
				}
				catch (Exception ex)
				{
				}
			}
		}

		private void SetRadiatorTypeAndVector(UIApplication uiApp, XYZ radiatorNormal, string installType, FamilyInstance fi)
		{
			bool flag = uiApp == null || fi == null;
			if (!flag)
			{
				XYZ xyz = XYZ.Zero;
				bool flag2 = installType.Equals("12") || installType.Equals("34");
				if (flag2)
				{
					xyz = radiatorNormal.CrossProduct(XYZ.BasisZ);
				}
				else
				{
					bool flag3 = installType.Equals("21") || installType.Equals("43");
					if (flag3)
					{
						xyz = radiatorNormal.CrossProduct(-XYZ.BasisZ);
					}
				}
				YJKRevitTools.SetInstanceParameter(uiApp, Path.Combine(Product.DataLocation, "HYShared Parameters.txt"), "散热器布置", "HYRadiatorType", BuiltInCategory.OST_MechanicalEquipment, false);
				Parameter parameter = fi.GetParameter("HYRadiatorType");
				bool flag4 = parameter != null;
				if (flag4)
				{
					parameter.Set(installType);
				}
				YJKRevitTools.SetInstanceParameter(uiApp, Path.Combine(Product.DataLocation, "HYShared Parameters.txt"), "散热器布置", "HYRadiatorVector", BuiltInCategory.OST_MechanicalEquipment, false);
				Parameter parameter2 = fi.GetParameter("HYRadiatorVector");
				bool flag5 = parameter2 != null;
				if (flag5)
				{
					parameter2.Set(xyz.Normalize().ToString());
				}
			}
		}

		private void RadiatorMirror(int rotateType, FamilyInstance radiator, XYZ locationCenter, Autodesk.Revit.DB.Document doc)
		{
			List<ElementId> list = new List<ElementId>();
			bool flag = ElementTransformUtils.CanMirrorElement(doc, radiator.Id);
			if (flag)
			{
				list.Add(radiator.Id);
			}
			bool flag2 = list == null || list.Count <= 0;
			if (!flag2)
			{
				YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
				switch (rotateType)
				{
				case 0:
				{
					Plane plane = RevitVersionFuncs.CreatePlanByOriginAndBasis(locationCenter, radiator.FacingOrientation, XYZ.BasisZ);
					ElementTransformUtils.MirrorElements(doc, list, plane, false);
					break;
				}
				case 2:
				{
					Plane plane2 = RevitVersionFuncs.CreatePlanByOriginAndBasis(locationCenter, XYZ.BasisX, XYZ.BasisY);
					ElementTransformUtils.MirrorElements(doc, list, plane2, false);
					break;
				}
				}
			}
		}

		public void SetRadiatorDimension(FamilyInstance fi, Autodesk.Revit.DB.Document doc, bool isUp = false)
		{
			YJKRevitTools.DeleteTagOfElement(doc, BuiltInCategory.OST_MechanicalEquipmentTags, fi);
			FamilySymbol familySymbol = YJKRevitTools.GetFamilySymbol(doc, "HY_散热器标记", BuiltInCategory.OST_MechanicalEquipmentTags);
			TagOrientation tagOrientation = 0;
			bool flag = fi.FacingOrientation.IsAlmostEqualTo(new XYZ(1.0, 0.0, 0.0)) || fi.FacingOrientation.IsAlmostEqualTo(new XYZ(-1.0, 0.0, 0.0));
			if (flag)
			{
				tagOrientation = 1;
			}
			bool flag2 = familySymbol != null;
			if (flag2)
			{
				IndependentTag independentTag = RevitVersionFuncs.NewTag(doc, doc.ActiveView, new Reference(fi), false, 0, tagOrientation, this.GetTagLoca(doc, fi, isUp));
				independentTag.ChangeTypeId(new ElementId(Convert.ToInt32(familySymbol.Id)));
				independentTag.HasLeader = false;
				independentTag.TagOrientation = this.GetTagOrientation(doc, fi);
			}
			else
			{
				doc.LoadFamily(UnifiedModified.GetMarkFamilyPath(doc, "HY_散热器标记"));
				IndependentTag independentTag2 = RevitVersionFuncs.NewTag(doc, doc.ActiveView, new Reference(fi), false, 0, tagOrientation, this.GetTagLoca(doc, fi, isUp));
				independentTag2.HasLeader = false;
				independentTag2.TagOrientation = this.GetTagOrientation(doc, fi);
			}
		}

		private XYZ GetTagLoca(Autodesk.Revit.DB.Document doc, FamilyInstance fi, bool isUp)
		{
			XYZ result = new XYZ();
			XYZ xyz = fi.FacingOrientation.Normalize();
			XYZ xyz2 = fi.HandOrientation.Normalize();
			XYZ xyz3 = new XYZ();
			bool flag = doc.ActiveView.UpDirection.AngleTo(xyz) > Math.PI*.5 || xyz.AngleTo(doc.ActiveView.UpDirection) > Math.PI*.5;
			if (flag)
			{
				xyz3 = -xyz;
			}
			else
			{
				xyz3 = xyz;
			}
			bool flag2 = !isUp;
			if (flag2)
			{
				result = (fi.Location as LocationPoint).Point - xyz3 * 0.9;
			}
			else
			{
				result = (fi.Location as LocationPoint).Point + xyz3 * 0.9;
			}
			return result;
		}

		private TagOrientation GetTagOrientation(Autodesk.Revit.DB.Document doc, FamilyInstance fi)
		{
			XYZ xyz = fi.FacingOrientation.Normalize();
			bool flag = xyz.AngleTo(doc.ActiveView.UpDirection) <= 0.78539816339744828 || doc.ActiveView.UpDirection.AngleTo(xyz) <= 0.78539816339744828 || xyz.AngleTo(doc.ActiveView.UpDirection) >= 2.3561944901923448 || doc.ActiveView.UpDirection.AngleTo(xyz) >= 2.3561944901923448;
			TagOrientation result;
			if (flag)
			{
				result = 0;
			}
			else
			{
				result = 1;
			}
			return result;
		}

		private double GetDuctCoilRotateAngle(List<Curve> curves, Autodesk.Revit.DB.Document doc = null)
		{
			bool flag = curves.IsEmpty<Curve>();
			double result;
			if (flag)
			{
				result = 0.0;
			}
			else
			{
				List<Curve> list = null;
				List<Curve> list2 = null;
				BussinessCommon.SeparateCloseCurves(curves, out list, out list2);
				bool flag2 = list.IsEmpty<Curve>();
				if (flag2)
				{
					result = 0.0;
				}
				else
				{
					Curve maxLengthCurve = this.GetMaxLengthCurve(list);
					Line unBoundVerticalLineFromCurve = BussinessCommon.GetUnBoundVerticalLineFromCurve(maxLengthCurve);
					Line verticalLineFromCurve = BussinessCommon.GetVerticalLineFromCurve(maxLengthCurve);
					bool flag3 = unBoundVerticalLineFromCurve == null || verticalLineFromCurve == null;
					if (flag3)
					{
						result = 0.0;
					}
					else
					{
						XYZ vec = (verticalLineFromCurve.GetEndPoint(1) - verticalLineFromCurve.GetEndPoint(0)).Normalize();
						double angleFromTwoVector = this.GetAngleFromTwoVector(vec, XYZ.BasisY);
						RevitPolygonFinder revitPolygonFinder = new RevitPolygonFinder();
						List<RevitPolygonDataBean> source = null;
						List<RevitPolygonDataBean> list3 = null;
						bool flag4 = !revitPolygonFinder.TryGetPolygon(list, out source, out list3, true, 2, false);
						if (flag4)
						{
							result = angleFromTwoVector;
						}
						else
						{
							List<RevitPolygonDataBean> list4 = (from a in source
							where a != null && a.Area != null
							select a).ToList<RevitPolygonDataBean>();
							bool flag5 = list4 == null || list4.Count <= 0;
							if (flag5)
							{
								result = angleFromTwoVector;
							}
							else
							{
								List<RevitPolygonDataBean> list5 = (from a in list4
								orderby a.Area descending
								select a).ToList<RevitPolygonDataBean>();
								bool flag6 = list5.Count <= 1;
								if (flag6)
								{
									result = angleFromTwoVector;
								}
								else
								{
									List<Curve> curvesFromRevitPolygonDataBean = BussinessCommon.GetCurvesFromRevitPolygonDataBean(list5[0]);
									List<Curve> curvesFromRevitPolygonDataBean2 = BussinessCommon.GetCurvesFromRevitPolygonDataBean(list5[1]);
									XYZ curvesCenterLocation = this.GetCurvesCenterLocation(curvesFromRevitPolygonDataBean);
									XYZ curvesCenterLocation2 = this.GetCurvesCenterLocation(curvesFromRevitPolygonDataBean2);
									bool flag7 = curvesCenterLocation == null || curvesCenterLocation2 == null || curvesCenterLocation.IsAlmostEqualTo(curvesCenterLocation2);
									if (flag7)
									{
										result = angleFromTwoVector;
									}
									else
									{
										IntersectionResult intersectionResult = unBoundVerticalLineFromCurve.Project(curvesCenterLocation);
										IntersectionResult intersectionResult2 = unBoundVerticalLineFromCurve.Project(curvesCenterLocation2);
										XYZ xyz = (intersectionResult2.XYZPoint - intersectionResult.XYZPoint).Normalize();
										xyz = this.RemoveZValue(xyz);
										bool flag8 = xyz.IsAlmostEqualTo(XYZ.Zero);
										if (flag8)
										{
											result = angleFromTwoVector;
										}
										else
										{
											result = this.GetAngleFromTwoVector(xyz, XYZ.BasisY);
										}
									}
								}
							}
						}
					}
				}
			}
			return result;
		}

		private double GetDuctCoilRotateAngleByMaxCurve(List<Curve> curves)
		{
			bool flag = curves.IsEmpty<Curve>();
			double result;
			if (flag)
			{
				result = 0.0;
			}
			else
			{
				Curve maxLengthCurve = this.GetMaxLengthCurve(curves);
				Line verticalLineFromCurve = BussinessCommon.GetVerticalLineFromCurve(maxLengthCurve);
				bool flag2 = verticalLineFromCurve == null;
				if (flag2)
				{
					result = 0.0;
				}
				else
				{
					XYZ xyz = (verticalLineFromCurve.GetEndPoint(1) - verticalLineFromCurve.GetEndPoint(0)).Normalize();
					xyz = this.RemoveZValue(xyz);
					double angleFromTwoVector = this.GetAngleFromTwoVector(xyz, XYZ.BasisY);
					result = angleFromTwoVector;
				}
			}
			return result;
		}

		private double GetRadiatorRotateAngleByMaxCurve(List<Curve> curves, double precision)
		{
			bool flag = curves.IsEmpty<Curve>();
			double result;
			if (flag)
			{
				result = 0.0;
			}
			else
			{
				Curve maxLengthCurve = this.GetMaxLengthCurve(curves);
				bool flag2 = maxLengthCurve == null;
				if (flag2)
				{
					result = 0.0;
				}
				else
				{
					XYZ xyz = (maxLengthCurve.GetEndPoint(1) - maxLengthCurve.GetEndPoint(0)).Normalize();
					xyz = this.RemoveZValue(xyz);
					double num = XYZ.BasisX.AngleTo(xyz);
					bool flag3 = Geometry.IsEqual(num, Math.PI, precision);
					if (flag3)
					{
						num = 0.0;
					}
					result = num;
				}
			}
			return result;
		}

		private double GetAngleFromTwoVector(XYZ vec1, XYZ vec2)
		{
			bool flag = vec1 == null || vec2 == null;
			double result;
			if (flag)
			{
				result = 0.0;
			}
			else
			{
				double num = vec1.AngleTo(vec2);
				XYZ xyz = vec2.CrossProduct(vec1);
				bool flag2 = xyz.Z >= 0.0;
				if (flag2)
				{
					result = num;
				}
				else
				{
					result = -num;
				}
			}
			return result;
		}

		private double GetDuctCoilRotateAngle(Autodesk.Revit.DB.Document doc, List<Curve> curves)
		{
			bool flag = curves.IsEmpty<Curve>();
			double result;
			if (flag)
			{
				result = 0.0;
			}
			else
			{
				Curve maxLengthCurve = this.GetMaxLengthCurve(curves);
				Line unBoundVerticalLineFromCurve = BussinessCommon.GetUnBoundVerticalLineFromCurve(maxLengthCurve);
				bool flag2 = unBoundVerticalLineFromCurve == null;
				if (flag2)
				{
					result = 0.0;
				}
				else
				{
					RevitPolygonFinder revitPolygonFinder = new RevitPolygonFinder();
					List<RevitPolygonDataBean> source = null;
					List<RevitPolygonDataBean> list = null;
					bool flag3 = !revitPolygonFinder.TryGetPolygon(curves, out source, out list, true, 2, false);
					if (flag3)
					{
						result = 0.0;
					}
					else
					{
						List<RevitPolygonDataBean> list2 = (from a in source
						where a != null && a.Area != null
						select a).ToList<RevitPolygonDataBean>();
						bool flag4 = list2 == null || list2.Count <= 0;
						if (flag4)
						{
							result = 0.0;
						}
						else
						{
							List<RevitPolygonDataBean> list3 = (from a in list2
							orderby a.Area descending
							select a).ToList<RevitPolygonDataBean>();
							bool flag5 = list3.Count <= 1;
							if (flag5)
							{
								result = 0.0;
							}
							else
							{
								List<Curve> curvesFromRevitPolygonDataBean = BussinessCommon.GetCurvesFromRevitPolygonDataBean(list3[0]);
								List<Curve> curvesFromRevitPolygonDataBean2 = BussinessCommon.GetCurvesFromRevitPolygonDataBean(list3[1]);
								XYZ curvesCenterLocation = this.GetCurvesCenterLocation(curvesFromRevitPolygonDataBean);
								XYZ curvesCenterLocation2 = this.GetCurvesCenterLocation(curvesFromRevitPolygonDataBean2);
								bool flag6 = curvesCenterLocation == null || curvesCenterLocation2 == null;
								if (flag6)
								{
									result = 0.0;
								}
								else
								{
									foreach (Curve curCurve in curvesFromRevitPolygonDataBean)
									{
										TestCommon.CreateModelCurve(curCurve, doc, new Autodesk.Revit.DB.Color(0, byte.MaxValue, 0), 1);
									}
									foreach (Curve curCurve2 in curvesFromRevitPolygonDataBean2)
									{
										TestCommon.CreateModelCurve(curCurve2, doc, new Autodesk.Revit.DB.Color(0, byte.MaxValue, 0), 1);
									}
									result = 0.0;
								}
							}
						}
					}
				}
			}
			return result;
		}

		private XYZ GetCurvesCenterLocation(List<Curve> curves)
		{
			bool flag = curves.IsEmpty<Curve>();
			XYZ result;
			if (flag)
			{
				result = null;
			}
			else
			{
				Curve maxLengthCurve = this.GetMaxLengthCurve(curves);
				XYZ vectorFromCurve = BussinessCommon.GetVectorFromCurve(maxLengthCurve);
				bool flag2 = vectorFromCurve == null;
				if (flag2)
				{
					result = null;
				}
				else
				{
					ToleranceManger toleranceManger = ToleranceManger.GetToleranceManger();
					double tolerance = toleranceManger.GetTolerance("末端快模-距离公差");
					Transform transformFromVector = this.GetTransformFromVector(vectorFromCurve, tolerance);
					Transform inverse = transformFromVector.Inverse;
					List<BoundingBoxUV> list = new List<BoundingBoxUV>();
					foreach (Curve c in curves)
					{
						BoundingBoxUV curveBoundingBoxUV = this.GetCurveBoundingBoxUV(c, transformFromVector);
						bool flag3 = curveBoundingBoxUV != null;
						if (flag3)
						{
							list.Add(curveBoundingBoxUV);
						}
					}
					BoundingBoxUV boundingBoxUV = this.MergeBoundingBoxUVs(list);
					bool flag4 = boundingBoxUV == null;
					if (flag4)
					{
						result = null;
					}
					else
					{
						UV uv = (boundingBoxUV.Max + boundingBoxUV.Min) / 2.0;
						XYZ xyz = new XYZ(uv.U, uv.V, 0.0);
						result = inverse.OfPoint(xyz);
					}
				}
			}
			return result;
		}

		private BoundingBoxUV MergeBoundingBoxUVs(List<BoundingBoxUV> boundingBoxUVs)
		{
			bool flag = boundingBoxUVs == null || boundingBoxUVs.Count <= 0;
			BoundingBoxUV result;
			if (flag)
			{
				result = null;
			}
			else
			{
				BoundingBoxUV boundingBoxUV = boundingBoxUVs[0];
				bool flag2 = boundingBoxUVs.Count > 1;
				if (flag2)
				{
					for (int i = 1; i < boundingBoxUVs.Count; i++)
					{
						boundingBoxUV = BoundingBoxUtilityMethod.BoundingBoxesMerge(boundingBoxUV, boundingBoxUVs[i]);
					}
				}
				result = boundingBoxUV;
			}
			return result;
		}

		private BoundingBoxUV GetCurveBoundingBoxUV(Curve c, Transform transform)
		{
			bool flag = c == null;
			BoundingBoxUV result;
			if (flag)
			{
				result = null;
			}
			else
			{
				List<XYZ> curveEndPoints = RevitCommonFunctions.GetCurveEndPoints(c);
				bool flag2 = curveEndPoints == null || curveEndPoints.Count != 2;
				if (flag2)
				{
					result = null;
				}
				else
				{
					XYZ start = transform.OfPoint(curveEndPoints[0]);
					XYZ end = transform.OfPoint(curveEndPoints[1]);
					result = this.CreateBoundingBoxUV(start, end);
				}
			}
			return result;
		}

		private BoundingBoxUV CreateBoundingBoxUV(XYZ start, XYZ end)
		{
			BoundingBoxUV boundingBoxUV = new BoundingBoxUV();
			double x = start.X;
			double y = start.Y;
			double x2 = end.X;
			double y2 = end.Y;
			bool flag = end.X < x;
			if (flag)
			{
				x = end.X;
			}
			bool flag2 = end.Y < y;
			if (flag2)
			{
				y = end.Y;
			}
			boundingBoxUV.Min = new UV(x, y);
			bool flag3 = start.X > x2;
			if (flag3)
			{
				x2 = start.X;
			}
			bool flag4 = start.Y > y2;
			if (flag4)
			{
				y2 = start.Y;
			}
			boundingBoxUV.Max = new UV(x2, y2);
			bool flag5 = boundingBoxUV.Max.IsAlmostEqualTo(boundingBoxUV.Min);
			BoundingBoxUV result;
			if (flag5)
			{
				result = null;
			}
			else
			{
				result = boundingBoxUV;
			}
			return result;
		}

		private Transform GetTransformFromVector(XYZ vector, double precision)
		{
			double num = vector.AngleTo(XYZ.BasisX);
			bool flag = Geometry.IsEqual(vector.Y, precision);
			Transform result;
			if (flag)
			{
				result = Transform.Identity;
			}
			else
			{
				bool flag2 = Geometry.LessThan(vector.Y, precision);
				Transform transform;
				if (flag2)
				{
					transform = Transform.CreateRotation(XYZ.BasisZ, num);
				}
				else
				{
					transform = Transform.CreateRotation(XYZ.BasisZ, -num);
				}
				result = transform;
			}
			return result;
		}

		private bool SetWindMouthSize(Element element, PointPosBlockWindMouthInfo blockInfo)
		{
			bool flag = element == null || blockInfo == null;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				FamilyInstance familyInstance = element as FamilyInstance;
				bool flag2 = familyInstance == null || familyInstance.Symbol == null || familyInstance.Symbol.Family == null;
				if (flag2)
				{
					result = false;
				}
				else
				{
					string name = familyInstance.Symbol.Family.Name;
					double sizeValue = this.GetSizeValue(blockInfo.BlockWidth);
					double sizeValue2 = this.GetSizeValue(blockInfo.BlockHeight);
					bool flag3 = Geometry.LessThan(Common.FeetToMM(sizeValue2), 50.0);
					if (flag3)
					{
						result = false;
					}
					else
					{
						string text = name;
						uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(text);
						if (num <= 2293425626u)
						{
							if (num <= 624669029u)
							{
								if (num != 191967364u)
								{
									if (num != 624669029u)
									{
										goto IL_251;
									}
									if (!(text == "方形风口"))
									{
										goto IL_251;
									}
									goto IL_223;
								}
								else if (!(text == "双层百叶风口"))
								{
									goto IL_251;
								}
							}
							else if (num != 1021866013u)
							{
								if (num != 1653062789u)
								{
									if (num != 2293425626u)
									{
										goto IL_251;
									}
									if (!(text == "方形散流器"))
									{
										goto IL_251;
									}
									goto IL_223;
								}
								else if (!(text == "板式排烟口"))
								{
									goto IL_251;
								}
							}
							else if (!(text == "单层百叶风口"))
							{
								goto IL_251;
							}
							this.SetCommonInstanceSize(familyInstance, sizeValue, sizeValue2);
							goto IL_253;
							IL_223:
							this.SetCommonInstanceSize(familyInstance, sizeValue, sizeValue);
						}
						else
						{
							if (num <= 2471572001u)
							{
								if (num != 2311027095u)
								{
									if (num != 2471572001u)
									{
										goto IL_251;
									}
									if (!(text == "侧风口"))
									{
										goto IL_251;
									}
								}
								else
								{
									if (!(text == "圆形散流器"))
									{
										goto IL_251;
									}
									this.SetCircleInstanceSize2(familyInstance, sizeValue);
									goto IL_253;
								}
							}
							else if (num != 2525999187u)
							{
								if (num != 3308886682u)
								{
									if (num != 3875882381u)
									{
										goto IL_251;
									}
									if (!(text == "防火风口"))
									{
										goto IL_251;
									}
								}
								else
								{
									if (!(text == "圆形风口"))
									{
										goto IL_251;
									}
									this.SetCircleInstanceSize(familyInstance, sizeValue);
									goto IL_253;
								}
							}
							else
							{
								if (!(text == "多叶排烟口"))
								{
									goto IL_251;
								}
								this.SetMultiLeafInstanceSize(familyInstance, sizeValue, sizeValue2);
								goto IL_253;
							}
							this.SetSideInstanceSize(familyInstance, sizeValue, sizeValue2);
						}
						IL_251:
						IL_253:
						result = true;
					}
				}
			}
			return result;
		}

		private List<CurveOutBoxType> GetCurveOutBoxTypeByFamily(string familyName)
		{
			List<CurveOutBoxType> list = new List<CurveOutBoxType>();
			uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(familyName);
			if (num > 2293425626u)
			{
				if (num <= 2471572001u)
				{
					if (num != 2311027095u)
					{
						if (num != 2471572001u)
						{
							return list;
						}
						if (!(familyName == "侧风口"))
						{
							return list;
						}
						list.Add(CurveOutBoxType.NoCloseRectangle);
						list.Add(CurveOutBoxType.CloseRectangle);
						list.Add(CurveOutBoxType.CloseCircle);
						return list;
					}
					else if (!(familyName == "圆形散流器"))
					{
						return list;
					}
				}
				else if (num != 2525999187u)
				{
					if (num != 3308886682u)
					{
						if (num != 3875882381u)
						{
							return list;
						}
						if (!(familyName == "防火风口"))
						{
							return list;
						}
						goto IL_158;
					}
					else if (!(familyName == "圆形风口"))
					{
						return list;
					}
				}
				else
				{
					if (!(familyName == "多叶排烟口"))
					{
						return list;
					}
					goto IL_158;
				}
				list.Add(CurveOutBoxType.CloseCircle);
				list.Add(CurveOutBoxType.CloseRectangle);
				list.Add(CurveOutBoxType.NoCloseRectangle);
				return list;
			}
			if (num <= 624669029u)
			{
				if (num != 191967364u)
				{
					if (num != 624669029u)
					{
						return list;
					}
					if (!(familyName == "方形风口"))
					{
						return list;
					}
				}
				else if (!(familyName == "双层百叶风口"))
				{
					return list;
				}
			}
			else if (num != 1021866013u)
			{
				if (num != 1653062789u)
				{
					if (num != 2293425626u)
					{
						return list;
					}
					if (!(familyName == "方形散流器"))
					{
						return list;
					}
				}
				else if (!(familyName == "板式排烟口"))
				{
					return list;
				}
			}
			else if (!(familyName == "单层百叶风口"))
			{
				return list;
			}
			IL_158:
			list.Add(CurveOutBoxType.CloseRectangle);
			list.Add(CurveOutBoxType.NoCloseRectangle);
			list.Add(CurveOutBoxType.CloseCircle);
			return list;
		}

		private bool GetBlockWidthAndHeight(PointPosBlockWindMouthInfo blockInfo, out double width, out double height)
		{
			width = 0.0;
			height = 0.0;
			bool flag = blockInfo == null;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				double blockWidth = blockInfo.BlockWidth;
				double blockHeight = blockInfo.BlockHeight;
				bool flag2 = blockWidth > blockHeight;
				if (flag2)
				{
					width = blockWidth;
					height = blockHeight;
				}
				else
				{
					width = blockHeight;
					height = blockWidth;
				}
				result = true;
			}
			return result;
		}

		private void SetCommonInstanceSize(FamilyInstance fi, double width, double height)
		{
			this.SetParaValue(fi, "风口宽度", width);
			this.SetParaValue(fi, "风口高度", height);
			double value = Common.MMToFeet(50.0);
			this.SetParaValue(fi, "风口厚度", value);
			double num = Common.MMToFeet(50.0);
			this.SetParaValue(fi, "喉口宽度", width - num);
			this.SetParaValue(fi, "喉口高度", height - num);
		}

		private void SetMultiLeafInstanceSize(FamilyInstance fi, double width, double height)
		{
			this.SetParaValue(fi, "风口宽度", width);
			this.SetParaValue(fi, "风口高度", height);
			double value = Common.MMToFeet(50.0);
			this.SetParaValue(fi, "风口厚度", value);
			double num = Common.MMToFeet(50.0);
			double num2 = Common.MMToFeet(300.0);
			this.SetParaValue(fi, "喉口宽度", width - num2);
			this.SetParaValue(fi, "喉口高度", height - num);
		}

		private void SetSideInstanceSize(FamilyInstance fi, double width, double height)
		{
			this.SetParaValue(fi, "风口宽度", width);
			this.SetParaValue(fi, "风口高度", width / 2.0);
			this.SetParaValue(fi, "风口厚度", height);
			double num = Common.MMToFeet(50.0);
			this.SetParaValue(fi, "喉口宽度", width - num);
			this.SetParaValue(fi, "喉口高度", width / 2.0 - num);
		}

		private void SetCircleInstanceSize(FamilyInstance fi, double diameter)
		{
			this.SetParaValue(fi, "风口直径", diameter);
			double value = Common.MMToFeet(50.0);
			this.SetParaValue(fi, "风口厚度", value);
			double num = Common.MMToFeet(50.0);
			this.SetParaValue(fi, "喉口直径", diameter - num);
		}

		private void SetCircleInstanceSize2(FamilyInstance fi, double diameter)
		{
			double value = Common.MMToFeet(50.0);
			this.SetParaValue(fi, "风口厚度", value);
			double num = Common.MMToFeet(300.0);
			this.SetParaValue(fi, "喉口直径", diameter - num);
		}

		private double GetSizeValue(double sizeValue)
		{
			int num = Convert.ToInt32(Common.FeetToMM(sizeValue).ToString("F0"));
			int num2 = 25;
			int num3 = (num - num % num2) / num2;
			bool flag = num3 % 2 == 0;
			int num4;
			if (flag)
			{
				num4 = 50 * num3 / 2;
			}
			else
			{
				num4 = 50 * (num3 + 1) / 2;
			}
			return Common.MMToFeet((double)num4);
		}

		private void SetWindMouthArrowType(Element element, int arrowType)
		{
			bool flag = element == null;
			if (!flag)
			{
				Parameter parameter = element.GetParameter("送风箭头可见性");
				Parameter parameter2 = element.GetParameter("回风箭头可见性");
				bool flag2 = arrowType == -1;
				if (flag2)
				{
					this.SetParaValue(parameter, 0);
					this.SetParaValue(parameter2, 1);
				}
				else
				{
					bool flag3 = arrowType == 1;
					if (flag3)
					{
						this.SetParaValue(parameter, 1);
						this.SetParaValue(parameter2, 0);
					}
					else
					{
						this.SetParaValue(parameter, 0);
						this.SetParaValue(parameter2, 0);
					}
				}
			}
		}

		private XYZ ScalePoint(XYZ location, double multiple)
		{
			return new XYZ(location.X / multiple, location.Y / multiple, location.Z / multiple);
		}

		private double GetParaDoubleValue(Element e, string paraName)
		{
			Parameter parameter = e.GetParameter(paraName);
			bool flag = parameter != null && (int)parameter.StorageType == 2;
			double result;
			if (flag)
			{
				result = parameter.AsDouble();
			}
			else
			{
				result = 0.0;
			}
			return result;
		}

		private void SetParaValue(FamilyInstance fi, string paraName, double value)
		{
			Parameter parameter = fi.GetParameter(paraName);
			bool flag = parameter != null && !parameter.IsReadOnly && (int)parameter.StorageType == 2;
			if (flag)
			{
				parameter.Set(value);
			}
		}

		private void SetParaValue(Parameter p, int value)
		{
			bool flag = p != null && !p.IsReadOnly && (int)p.StorageType == 1;
			if (flag)
			{
				p.Set(value);
			}
		}

		private void SetPara(Element elem, string paramName, double paramValue)
		{
			Parameter parameter = elem.GetParameter(paramName);
			bool flag = parameter != null && !parameter.IsReadOnly;
			if (flag)
			{
				parameter.Set(paramValue);
			}
		}

		private void SetPara(Element elem, string paramName, int paramValue)
		{
			Parameter parameter = elem.GetParameter(paramName);
			bool flag = parameter != null && !parameter.IsReadOnly;
			if (flag)
			{
				parameter.Set(paramValue);
			}
		}

		private void SetPara(Element elem, string paramName, string paramValue)
		{
			Parameter parameter = elem.GetParameter(paramName);
			bool flag = parameter != null && !parameter.IsReadOnly;
			if (flag)
			{
				parameter.Set(paramValue);
			}
		}

		private Curve GetMaxLengthCurve(List<Curve> curves)
		{
			bool flag = curves == null || curves.Count <= 0;
			Curve result;
			if (flag)
			{
				result = null;
			}
			else
			{
				List<Curve> list = (from a in curves
				orderby a.Length descending
				select a).ToList<Curve>();
				foreach (Curve curve in list)
				{
					bool flag2 = curve is Arc || curve is Ellipse;
					if (!flag2)
					{
						return curve;
					}
				}
				result = null;
			}
			return result;
		}

		private List<Curve> GetCurvesFromPoints(List<XYZ> points)
		{
			bool flag = points == null || points.Count <= 0;
			List<Curve> result;
			if (flag)
			{
				result = new List<Curve>();
			}
			else
			{
				List<Curve> list = new List<Curve>();
				for (int i = 0; i < points.Count - 1; i++)
				{
					bool flag2 = i == 0;
					if (flag2)
					{
						Curve item = Line.CreateBound(points[points.Count - 1], points[i]);
						list.Add(item);
					}
					Curve item2 = Line.CreateBound(points[i], points[i + 1]);
					list.Add(item2);
				}
				result = list;
			}
			return result;
		}

		private XYZ RemoveZValue(XYZ point)
		{
			return new XYZ(point.X, point.Y, 0.0);
		}

		private void CheckBlockIsMirrored(XYZ scale, out bool isMirroredX, out bool isMirroredY)
		{
			isMirroredX = false;
			isMirroredY = false;
			bool flag = this.CheckValue(scale.X) < 0;
			if (flag)
			{
				isMirroredX = true;
			}
			bool flag2 = this.CheckValue(scale.Y) < 0;
			if (flag2)
			{
				isMirroredY = true;
			}
		}

		private double GetRightAngle(double angle)
		{
			ToleranceManger toleranceManger = ToleranceManger.GetToleranceManger();
			double tolerance = toleranceManger.GetTolerance("末端快模-角度公差");
			bool flag = Geometry.IsEqual(angle, 0.0, tolerance);
			double result;
			if (flag)
			{
				result = angle;
			}
			else
			{
				bool flag2 = angle <= 0.0;
				double num;
				for (num = Math.Abs(angle); num > Math.PI*2; num -= Math.PI*2)
				{
				}
				result = (flag2 ? (-num) : num);
			}
			return result;
		}

		private int CheckValue(double value)
		{
			ToleranceManger toleranceManger = ToleranceManger.GetToleranceManger();
			double tolerance = toleranceManger.GetTolerance("末端快模-数字公差");
			bool flag = Geometry.IsEqual(value, 0.0, tolerance);
			int result;
			if (flag)
			{
				result = 0;
			}
			else
			{
				bool flag2 = value > 0.0;
				if (flag2)
				{
					result = 1;
				}
				else
				{
					result = -1;
				}
			}
			return result;
		}
	}
}
